package com.easydl.project.action;


import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.easydl.project.model.EasyPictureDiscernVO;
import com.easydl.project.model.EasydlAccessTokenVO;
import com.easydl.project.service.EasyLockTokenService;
import com.easydl.project.service.EasyTokenService;
import com.easydl.project.service.EasydlService;

@Controller
@RequestMapping("/easydl")
public class EasydlController {
	
	@Autowired
	private ApplicationContext applicationContext;

	Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private EasydlService easydlService;
	
	
//	@Autowired
//	private EasyTokenService easyTokenService;
	
	@Autowired
	private EasyLockTokenService easyTokenService;

	@RequestMapping("/mask")
	@ResponseBody
	public List<EasyPictureDiscernVO> mask(MultipartFile file) throws Exception {
		logger.info(file.getName());
		logger.info(file.getOriginalFilename());
		byte[] arrByte = file.getBytes();
		logger.info("length:" + arrByte.length);
		return easydlService.maskRecognition(arrByte);
	}
	
	@RequestMapping("/token")
	@ResponseBody
	public EasydlAccessTokenVO getAccessToken() throws Exception {
		//从本地缓存获取
		EasydlAccessTokenVO easydlAccessTokenVO=easyTokenService.getToken();
		return easydlAccessTokenVO;
	}
	
	@RequestMapping("/bean")
	@ResponseBody
	public String[] getGoods() {
		String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
		for(String name:beanDefinitionNames){
			logger.info(name);
			if("easyConcurrentMapCache".equals(name)) {
				ConcurrentMapCache concurrentMapCache=(ConcurrentMapCache)applicationContext.getBean(name);
				logger.info("ss:"+concurrentMapCache.get("easydl::access_token"));
			}
		}
		return beanDefinitionNames;
	}
}
